package com.admin.controller;

import com.admin.entity.Admin;
import com.admin.service.IAdminService;
import com.admin.service.ITongjiService;
import com.bean.ResponseBean;
import com.token.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 统计模块
 */
@RestController
@RequestMapping("/admin/tongji")
public class TongjiController {
    @Autowired
    private ITongjiService tongjiService;

    @Autowired
    private IAdminService adminService;
    /**
     * 根据用户id查询统计终端数据
     * @param token 从这里取用户的电话
     * @return 在线总时长，绑定终端数，在线数，离线数；字段如下：
     *"zhongduanzongtime","zhongduanshu","zaixianshu","lixianshu"
     */
    @RequestMapping("/zhongduan")
    public ResponseBean tongJizhongduanshuju(String token){
        String username = JwtUtil.getUsername(token);
        Admin admin = adminService.getAdminByUserName(username);
        Map tongjimap = tongjiService.tongJizhongduan(admin.getAdminId());
        return new ResponseBean(200,null,tongjimap);
    }
}
